package com.starlink.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starlink.model.domain.MallBooksOrderDetailsDO;
import com.starlink.model.request.MallBooksOrderDetailsRequest;
import com.starlink.model.vo.BookReadingRecordVO;
import com.starlink.model.vo.mall.MallOrderDetailListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author zhanghong
 */
@Repository
public interface MallBooksOrderDetailsMapper extends BaseMapper<MallBooksOrderDetailsDO> {
    MallBooksOrderDetailsDO selectDOById(Long id);
    List<MallBooksOrderDetailsDO> selectDOList(MallBooksOrderDetailsDO mallBooksOrderDetails);
    int insertDO(MallBooksOrderDetailsDO mallBooksOrderDetails);
    int batchInsertDO(List<MallBooksOrderDetailsDO> mallBooksOrderDetailsDOList);
    int updateDO(MallBooksOrderDetailsDO mallBooksOrderDetails);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from mall_books_order_details",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") MallBooksOrderDetailsRequest param);
    @Select({"<script>",
            "   select * from mall_books_order_details",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<MallBooksOrderDetailsDO> pageQuery(@Param("param") MallBooksOrderDetailsRequest param, @Param("limit") int limit, @Param("offset") long offset);

    List<BookReadingRecordVO> pageQueryNot(@Param("userId")Long userId);

    void updateRecord(@Param("bookId")Long bookId, @Param("orderId")Long orderId);

    Map<String, Long> selectQuantity( @Param("orderId")Long orderId,@Param("type") Integer type);

    Long selectSpecificationId( @Param("orderId")Long orderId);

    void deleteBookOrderDetaile(@Param("orderId")Long orderId);

    MallOrderDetailListVO selectBookOrderDetail(@Param("orderId")Long orderId);

    void updateIsRefunds(@Param("orderId") Long orderId);

    void deletedByOrderIds(String[] ids);

    List<Long> selectInventoryBySpecificationId(@Param("specificationId")Long specificationId);
}
